package com.wmz.picture.exception;

/**
 * @author lihechun
 * @version 1.0
 * @description: 异常抛出工具类：实现优雅的抛出异常
 * @date: 2024/12/13 0:34
 */
public class ThrowUtils {
    /**
     * 条件成立抛出异常
     * @param condition 条件
     * @param runtimeException 异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }
    /**
     * 条件成立抛出异常
     * @param condition 条件
     * @param errorCode 错误码
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition,new BusinessException(errorCode));
    }
    /**
     * 条件成立抛出异常
     * @param condition 条件
     * @param errorCode 错误码
     * @param message   错误信息
     */
    public static void throwIf(boolean condition, ErrorCode errorCode,String message) {
        throwIf(condition,new BusinessException(errorCode,message));
    }
}
